#include "InfoCollectionBase.h"

InfoCollectionBase::InfoCollectionBase(QObject *parent)
    :QObject(parent)
{

}

void InfoCollectionBase::getOnePopenResult(const QString &shellCmd, QString &result)
{
    QList<QString> resultList;
    getPopenResult(shellCmd, resultList);
    if (!resultList.isEmpty()) {
        result = resultList.first();
    } else {
        result = "";
    }
}

void InfoCollectionBase::getPopenResult(const QString &shellCmd, QList<QString> &result)
{
    char  resultInfo[s_maxStrLen];
    FILE *fp = popen(shellCmd.toStdString().c_str(), "r");
    if(fp == nullptr)
    {
        return;
    }
    while (fgets(resultInfo, s_maxStrLen, fp) != NULL) {
        QString resultTmp = QString::fromLatin1(resultInfo);
        if (!resultTmp.isNull()) {
            result.push_back(resultTmp.simplified());
        }
    }
    pclose(fp);

}
